package com.avic.rong.fragment;

import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.avic.rong.R;
import com.avic.rong.activity.BootstrapActivity;
import com.avic.rong.activity.interest.FocusFirstActivity;
import com.avic.rong.activity.login.UserProtocolActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Creater: Created by wangyz on 2017/2/22.
 * Email: 936804097@qq.com
 */

public class BootstrapThreeView extends LinearLayout {


    @BindView(R.id.cb_protocol)
    CheckBox cb_protocol;
    @BindView(R.id.tv_protocol)
    TextView tv_protocol;

    private Context mContext;

    public BootstrapThreeView(Context context) {
        this(context, null);
    }

    public BootstrapThreeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BootstrapThreeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.initView(context);
    }

    private void initView(final Context context) {
        this.mContext = context;
        LayoutInflater inflater = LayoutInflater.from(context);
        View viewOne = inflater.inflate(R.layout.view_bootstrap_three, this);
        ButterKnife.bind(this, viewOne);
        tv_protocol.setText(Html.fromHtml("<u>已同意《融融软件许可及服务协议》及《隐私政策》</u>"));
    }

    @OnClick({R.id.btn_go, R.id.tv_protocol})
    public void goMainPage(View view) {
        int viewId = view.getId();
        switch (viewId) {
            case R.id.btn_go:
                if (cb_protocol.isChecked()) {
                    this.mContext.startActivity(FocusFirstActivity.queryIntent(mContext));
                    ((BootstrapActivity)mContext).finish();
                } else {
                    Toast toast = Toast.makeText(mContext, "请阅读《融融软件许可及服务协议》及《隐私政策》!", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.show();
                }
                break;
            case R.id.tv_protocol:
                mContext.startActivity(UserProtocolActivity.queryIntent(mContext));
                ((BootstrapActivity)mContext).finish();
                break;
        }

    }


}
